using JSOCTNetSDK.XmppTaskModel;
using JSST.Framework.DBAccess;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace JSOCTNetSDK.XmppTask
{
	public class TaskVersionFun
	{
		public TaskVersion GetModel(int ID)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select  top 1 ID,VersionName from SYNC.TaskVersion ");
			stringBuilder.Append(" where ID=@ID");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@ID", SqlDbType.Int, 4)
			};
			array[0].Value = ID;
			new TaskVersion();
			DataTable dataTableText = MSSQL.GetDataTableText(stringBuilder.ToString(), array);
			if (dataTableText.Rows.Count > 0)
			{
				return this.DataRowToModel(dataTableText.Rows[0]);
			}
			return null;
		}

		private TaskVersion DataRowToModel(DataRow row)
		{
			TaskVersion taskVersion = new TaskVersion();
			if (row != null)
			{
				if (row["ID"] != null && row["ID"].ToString() != "")
				{
					taskVersion.ID = int.Parse(row["ID"].ToString());
				}
				if (row["VersionName"] != null)
				{
					taskVersion.VersionName = row["VersionName"].ToString();
				}
			}
			return taskVersion;
		}

		public DataTable GetList(string strWhere)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select ID,VersionName ");
			stringBuilder.Append(" FROM SYNC.TaskVersion ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			return MSSQL.GetDataTableText(stringBuilder.ToString(), new SqlParameter[0]);
		}
	}
}
